package leetcode;


import org.junit.Test;

import java.util.logging.Logger;

/**
 * @Description：
 * @Author：LiDong
 * @Create：2021/4/15
 * @Version：1.0.0
 */
public class Test213 {

    private static final Logger logger = Logger.getLogger(String.valueOf(Test213.class));

    public int rob(int[] nums) {
        if (nums.length == 0) {
            return 0;
        }
        if (nums.length == 1) {
            return nums[0];
        }
        if (nums.length == 2) {
            return Math.max(nums[0], nums[1]);
        }


        return Math.max(doMax(nums, 0, nums.length - 2), doMax(nums, 1, nums.length - 1));
    }

    private int doMax(int[] nums, int start, int end) {
        int first = nums[start];
        int second = Math.max(nums[start], nums[start + 1]);
        for (int i = start + 2; i <= end; i++) {
            int temp = second;
            second = Math.max(second, first + nums[i]);
            first = second;
        }
        return second;
    }

    @Test
    public void test() {
        int[] arr = {1, 2, 3, 1};
        logger.info(String.valueOf(rob(arr)));
    }

}
